package com.xueke.crawler.dao;

import com.xueke.crawler.model.DocRelation;
import com.xueke.crawler.model.SubjectTree;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by weibo on 2017/5/13.
 *
 * @author weibo.qin
 * @version 2017/5/13
 */
@Mapper
public interface DocRelationMapper {


    @Insert("insert into tbl_xueke_relation_2017(leafId,docId,isDownload,isRecordDetail,cid,level,ctime)" +
        "values(#{leafId},#{docId},#{isDownload},#{isRecordDetail},#{cid},#{level},NOW())")
    public void insertDocRelation(DocRelation docRelation);


    @Select("select * from tbl_xueke_relation_2017 where docId >= #{start} and docId <#{end} and level=#{level} and " +
        "isDownload=0 order by id limit #{s},#{offset}")
    public List<DocRelation> query2DownloadDocRelation(@Param("start") int start, @Param("end") int end, @Param
        ("level") int level,@Param("s") int s,@Param("offset") int offset);

    @Update("update tbl_xueke_relation_2017 set isRecordDetail=1 where docId = #{docId} ")
    public int updateRecordDetailStatus(@Param("docId") int docId);
    
    @Update("update tbl_xueke_relation_2017 set isDownload=1 where docId = #{docId} ")
    public int updateDownloadStatus(@Param("docId") int docId);

    @Update("update tbl_xueke_relation_2017 set isDownload=0 where docId = #{docId} ")
    public int resetDownloadStatus(@Param("docId") String docId);


    @Update("update tbl_xueke_relation_2017 set isDownload=-1 where docId = #{docId} ")
    public int updateInvalidDoc(@Param("docId") String docId);


    @Select("select * from tbl_xueke_relation_2017 where isRecordDetail=0 order by id desc limit #{start},#{offset}")
    public List<DocRelation> query4FillDocInfo(@Param("start") int start , @Param("offset") int offset);
}
